package com.ag.oa.core.service.impl;

import com.ag.oa.core.dao.IMessageDao;
import com.ag.oa.core.dao.IUserFeedbackDao;
import com.ag.oa.core.entity.vo.UserFeedbackVO;
import com.ag.oa.core.service.IUserFeedBackService;
import com.ag.oa.util.CustomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("userFeedBackServiceImpl")
public class UserFeedBackServiceImpl implements IUserFeedBackService {


    @Autowired
    private IUserFeedbackDao userFeedbackDao;

    @Autowired
    private IMessageDao messageDao;


    @Override
    public void createUserFeedback(UserFeedbackVO vo) {
        // 1. 先新增用户反馈记录
        userFeedbackDao.createUserFeedback(vo);

        // 类型7，表示用户反馈消息
        Integer type = 7;
        // 发送者
        Integer fromUserId = vo.getCreatedBy();
        // 接收者，0代表系统管理员
        List<Integer> toUserIdList = new ArrayList<>();
        toUserIdList.add(0);
        // 消息批次
        String batchId = CustomUtil.getUUID32();
        // 反馈消息id
        Integer feedbackId = vo.getId();

        // 2. 再新增用户反馈消息
        messageDao.saveNewMessage(type, fromUserId, toUserIdList, null, null, 0, batchId, null, 0, feedbackId);
    }

    @Override
    public List<UserFeedbackVO> getFeedbackList(Integer userId, Integer page) {
        Integer pageSize = 20;
        return userFeedbackDao.getFeedbackList(userId, page*pageSize, pageSize);
    }

    @Override
    public UserFeedbackVO getFeedbackDetail(Integer userId, Integer feedbackId) {
        return userFeedbackDao.getFeedbackDetail(userId, feedbackId);
    }


}
